package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.CustomTemplateFieldAddDTO;
import org.jsola.hr.dto.CustomTemplateFieldUpdateDTO;
import org.jsola.hr.entity.CustomTemplateFieldDO;
import org.jsola.hr.query.CustomTemplateFieldQuery;
import org.jsola.hr.service.ICustomTemplateFieldService;
import org.jsola.hr.vo.CustomTemplateFieldVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 自定义模板字段
 *
 * @author zhr
 */
@Component
public class CustomTemplateFieldTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICustomTemplateFieldService customTemplateFieldService;

    /**
     * 生成add测试数据
     * @return CustomTemplateFieldAddDTO
     */
    public CustomTemplateFieldAddDTO getCustomTemplateFieldAddDTO(){
        CustomTemplateFieldAddDTO customTemplateFieldAddDTO = new CustomTemplateFieldAddDTO();
        customTemplateFieldAddDTO.setSort(SafeKit.getInteger(getRandomValue("int",10)));
        customTemplateFieldAddDTO.setIsDefault(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        customTemplateFieldAddDTO.setIsEdit(SafeKit.getInteger(getRandomValue("int",2)));
        customTemplateFieldAddDTO.setFieldType(SafeKit.getInteger(getRandomValue("int",2)));
        customTemplateFieldAddDTO.setFieldCode(getRandomValue("varchar",32));
        customTemplateFieldAddDTO.setFieldName(getRandomValue("varchar",32));
        customTemplateFieldAddDTO.setIsRequired(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        customTemplateFieldAddDTO.setIsNecessary(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        customTemplateFieldAddDTO.setIsOpen(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        customTemplateFieldAddDTO.setModuleName(getRandomValue("varchar",50));
        customTemplateFieldAddDTO.setModuleCode(getRandomValue("varchar",30));
        customTemplateFieldAddDTO.setCompanyId(getRandomValue("varchar",32));
        customTemplateFieldAddDTO.setTemplateId(getRandomValue("varchar",32));
        customTemplateFieldAddDTO.setType(SafeKit.getInteger(getRandomValue("int",1)));
        return customTemplateFieldAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CustomTemplateFieldUpdateDTO
     */
    public CustomTemplateFieldUpdateDTO getCustomTemplateFieldUpdateDTO(CustomTemplateFieldVO customTemplateFieldVO){
        return customTemplateFieldService.selectDOById(customTemplateFieldVO.getId(), SITE_ID).to(CustomTemplateFieldUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CustomTemplateFieldQuery
     */
    public CustomTemplateFieldQuery getCustomTemplateFieldQuery() {
        CustomTemplateFieldQuery customTemplateFieldQuery = new CustomTemplateFieldQuery();
        List<CustomTemplateFieldDO> customTemplateFieldDOList = customTemplateFieldService.list(new CustomTemplateFieldDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(customTemplateFieldDOList)) {
            CustomTemplateFieldDO customTemplateFieldDO = customTemplateFieldDOList.get(0);
            customTemplateFieldQuery = customTemplateFieldDO.to(CustomTemplateFieldQuery.class);
        }
        return customTemplateFieldQuery;
    }

    /**
     * 保存示例
     * @return CustomTemplateFieldVO
     */
    public CustomTemplateFieldVO saveCustomTemplateFieldExample(){
        CustomTemplateFieldAddDTO addDTO = this.getCustomTemplateFieldAddDTO();
        CustomTemplateFieldVO customTemplateFieldVO = customTemplateFieldService.save(addDTO,buildTokenUser());
        return customTemplateFieldVO;
    }


}

